﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMathLibrary.NonlinearEquationSolvers;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class provides the finding of all poles of a rational polynomial. 
    /// </summary>
    [Serializable]
    public class PoleFinder
    {
        /// <summary>
        /// The polynomial from which she poles should be found.
        /// </summary>
        private SimpleRationalPolynomial polynomial;

        /// <summary>
        /// Initializes a new instance of the <see cref="PoleFinder"/> class.
        /// </summary>
        /// <param name="polynomial">The polynomial from which she poles should be found.</param>
        public PoleFinder(SimpleRationalPolynomial polynomial)
        {
            if (polynomial == (SimpleRationalPolynomial) null)
            {
                throw new ArgumentNullException("polynomial");
            }

            this.polynomial = polynomial;
        }

        /// <summary>
        /// Gets or sets the polynomial from which she poles should be found.
        /// </summary>
        /// <value>The polynomial from which she poles should be found.</value>
        public SimpleRationalPolynomial Polynomial
        {
            get { return polynomial; }
            set { polynomial = value; }
        }

        /// <summary>
        /// Finds the poles of the specified polynomial.
        /// </summary>
        /// <returns>The poles of the polynomial.</returns>
        public ComplexNumber[] FindPoles()
        {
            BairstowComplexRootFinder rootFinder = new BairstowComplexRootFinder(this.polynomial.DenominatorPolynomial);

            return rootFinder.FindRoots();
        }
    }
}